﻿using System;
using System.Globalization;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Xml;
using System.Reflection;
using ebookreader.Resources;
using ebookreader;

namespace ebookreader
{
    class CreditsMenu : Menu
    {
        //MyButton title;

        SpriteFont extralarge, large, medium, small;
        State currentState;
        public CreditsMenu(Game game)
            : base(game)
        {
        }

        public override void Initialize()
        {
            sprite_batch = Game.Services.GetService(typeof(SpriteBatch)) as SpriteBatch;            
            //input_manager = new InputManager(Game);
            //Game.Components.Add(input_manager);
            input_manager.OnTap += new InputManager.Tap(OnTap);
            currentState = Game.Services.GetService(typeof(State)) as State;
            base.Initialize();
        }


        Texture2D vs_logo, menu_button, background, background_er, back;
        SpriteFont font, font_names, font_rule;
        List<string> devel, graphs;
        protected override void LoadContent()
        {
            font = Game.Content.Load<SpriteFont>("Fonts/menu");
            font_names = Game.Content.Load<SpriteFont>("Fonts/menu_sx");
            font_rule = Game.Content.Load<SpriteFont>("Fonts/menu_piccolo");
            //font_menu_sx = Game.Content.Load<SpriteFont>("Fonts/menu_sx");
            back = Game.Content.Load<Texture2D>("Definitivo/back");
            background = Game.Content.Load<Texture2D>("Definitivo/background");
            background_er = Game.Content.Load<Texture2D>("todo/logo2");
            vs_logo = Game.Content.Load<Texture2D>("Definitivo/vs_logo");

            menu_button = Game.Content.Load<Texture2D>("Definitivo/menu_button");

            //input_manager.OnTap += new InputManager.Tap(OnTap);

            devel = new List<string>() { "GIUSEPPE MAGGIORE", "ANDREA GASPARETTO", "LUCA COSMO", "FRANCESCO BOSCARIOL" };
            graphs = new List<string>() { "LAURA STEFANI" };


            var back_button = new TextureButton(sprite_batch, back, Vector2.One * 1, currentState.options);
            back_button.OnPress += new Press(
                (me) => { ScreenManager.SelectMainMenu(Game); }
                );
            entries.Add(back_button);

            base.LoadContent();
        }

        public override void Update(GameTime gameTime)
        {

            if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back))
            {
                ScreenManager.SelectMainMenu(Game);
            }
            base.Update(gameTime);
        }



        public override void Draw(GameTime gameTime)
        {
            sprite_batch.Begin();
            sprite_batch.Draw(background, GraphicsDevice.Viewport.Bounds, Color.White);
            sprite_batch.Draw(background_er, new Vector2(644,23), Color.White);
            sprite_batch.Draw(vs_logo, new Vector2(54,181), Color.White);


            sprite_batch.Draw(menu_button, new Vector2(94, 82), Color.White);
            sprite_batch.DrawString(font, Lang.MM_Credits, new Vector2(94 + 20, 82 + menu_button.Height / 2 - font.MeasureString(Lang.MM_Credits).Y / 2), Color.White);

           
            var devel_position = new Vector2(575,65);


            for(int i=0; i<devel.Count; i++)
            {
                var name = devel[i].Split(new char[]{' '});
                for(int j=0; j<name.Length; j++)
                {
                    var sub_name = name[j];
                    var size = font_names.MeasureString(sub_name);
                    sprite_batch.DrawString(font_names, sub_name, devel_position - Vector2.UnitX *size.X , Color.White);
                    devel_position.Y += size.Y/2+2;
                }
                devel_position.Y += 10;
            }
            sprite_batch.DrawString(font_rule, "DEVELOPERS", devel_position - Vector2.UnitX * font_rule.MeasureString("DEVELOPERS").X, Color.White);
            devel_position.Y += 12 + font_rule.MeasureString("D").Y;

            for (int i = 0; i < graphs.Count; i++)
            {
                var name = graphs[i].Split(new char[] { ' ' });
                for (int j = 0; j < name.Length; j++)
                {
                    var sub_name = name[j];
                    var size = font_names.MeasureString(sub_name);
                    sprite_batch.DrawString(font_names, sub_name, devel_position - Vector2.UnitX * size.X, Color.White);
                    devel_position.Y += size.Y / 2 + 2;
                }
                devel_position.Y += 10;
            }
            sprite_batch.DrawString(font_rule, "GRAPHICS", devel_position - Vector2.UnitX * font_rule.MeasureString("GRAPHICS").X, Color.White);

            sprite_batch.End();
            base.Draw(gameTime);
        }


    }
}
